﻿
@{
    ViewData["Title"] = "CustomerDataIndex";
    Layout = null;
}


<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />


    @* 查询条件 *@
    <form class="layui-form layui-row layui-col-space16">
        <div class="layui-col-sm3">
            <input type="text" name="customerName" placeholder="客户姓名" class="layui-input">
        </div>

        <button type="button" class="layui-btn layui-bg-blue" id="searchButton">查询</button>
        <button type="button" class="layui-btn">重置</button>

        <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-custom" onclick="addReturn()">
            添加
        </button>

    </form>

    

  

    @* 显示数据表格 *@
    <table class="layui-hide" id="mainData" lay-filter="mainData" style="margin-top: 20px;margin-left: 20px">
    </table>


    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="upd">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>


<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>

<script>

    layui.use('table', function () {
       var table = layui.table;
       var form = layui.form;
       var laydate = layui.laydate;

       function show() {
           table.render({
           elem: '#mainData',
           url: '/MainData/GetCustomerDataList', // 实际接口地址
           page: true, // 开启分页
           limit: 10, // 每页默认显示的条数
           limits: [10, 20, 30], // 每页条数的选择项
           cols: [
               [
                  { field: 'customerCode', title: '客户编码', width: 120,id:'customerCode' },
                  { field: 'customerName', title: '客户名称', width: 120,id:'customerName' },
                  { field: 'customerNickName', title: '客户简称' , width: 120,id:'customerNickName' },
                  { field: 'customerType', title: '客户类型' , width: 120,id:'customerType' },
                  { field: 'customerTel', title: '客户电话' , width: 120,id:'customerTel' },
                   { field: 'contact', title: '联系人' , width: 120,id:'contact' },
                    { field: 'contactTel', title: '联系人-电话' , width: 120,id:'contactTel' },

                    {
                        field: 'isNot',
                        title: '是否启用',
                        templet: function (d) {
                            return d.isNot ? '是' : '否';
                        },
                        width: 110,
                        key: 'isNot' // 使用 key 来标识这一列
                    },
              
                   { title: '操作', fixed: 'right', width: 200, align: 'center', toolbar: '#barDemo' }
               ]
          ],
          parseData: function (res) {
              return {
                  code: res.code,
                  count: res.data.rowCount,
                  data: res.data.queryable
              };
          },
           })
           }
           show();

               //查询
    $("#searchButton").on("click", function() {
 
        show();
    });


            table.on('tool(mainData)', function(obj) {
            var data = obj.data;//获取当前行数据
            console.log(data,"当前行数据");


        if (obj.event === 'delete') {
            //在这里进行删除操作
 
        layer.confirm('确定要删除吗？', {
             btn: ['确定', '取消'] //按钮
         }, function () {
             $.ajax({
                 url: '/MainData/CustomerDataDelete',
                 type: 'post',
                 data: {
                   id: data.id
                },
                 success: function (res) {
            
                     if (res.msg == '删除成功') {
                         layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                             location.reload(); //刷新页面
                         });
                     } else {
                         layer.msg(res.msg, { icon: 2, time: 1000 });
                     }
                 }
             });
         }, function () {
             layer.msg('已取消', { icon: 1, time: 1000 });
         });
        }

        if(obj.event === 'upd'){
     
          //iframe层
         layer.open({
           type: 2,
           title: '修改客户数据',
           shadeClose: true,
           shade: 0.5,
           area: ['600px', '60%'],
           content: '/MainData/UpdateCustomerDatatView?id='+ data.id, //iframe的src
           end: function () {
               // iframe层关闭后刷新页面
               location.reload(); // 刷新页面
           }
       });
        }

    });

    });

      //添加
     function addReturn() {
  
          //iframe层
       layer.open({
           type: 2,
           title: '添加客户数据',
           shadeClose: true,
           shade: 0.5,
           area: ['800px', '100%'],
           content: '/MainData/CustomerDataAddIndex', //iframe的src
           end: function () {
               // iframe层关闭后刷新页面
               location.reload(); // 刷新页面
           }
       });
     }

    


</script>
